import {reqCategoryList, reqFloorList, reqGetBannerList} from '@/api'
//hone模块的小仓库
//state:仓库存储数据的地方
const state = {
    //state数据中默认初始值 根据接口返回值初始化
    categoryList: [],
    //轮播图的数据
    bannerList: [],
    floorList: []
};
//mutations:修改state的唯一手段
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    GETFLOORLIST(state, floorList) {
        state.floorList = floorList

    }
};
//action:处理action, 可以书写自己的业务逻辑，也可以处理异步
const actions = {
    //获取三级列表    
    async categoryList({commit}) {
        let result = await reqCategoryList()
        if (result.code === 200) {
            commit("CATEGORYLIST", result.data);
        }
    },
    //获取首页轮播图的数据
    async getBannerList({commit}) {
        let result = await reqGetBannerList()
        if (result.code === 200) {
            commit("GETBANNERLIST", result.data);
        } else{
            return Promise.reject(new Error('faile'))
        }
    },
    //获取floor轮播图的数据
    async getFloorList({commit}) {
        let result = await reqFloorList()
        if (result.code === 200) {
            commit("GETFLOORLIST", result.data);
        }
    }
};
//getters:理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters = {};

//对外暴露Store类的一个实例
export default {
    state,
    mutations,
    actions,
    getters
}